//
//  HKShareAvaudioManager.m
//  HKTimeKitApp
//
//  Created by huzhaoke1 on 2023/11/3.
//

#import "HKShareAvaudioManager.h"

@implementation HKShareAvaudioManager

+ (instancetype)sharedInstance {
    static HKShareAvaudioManager *instance;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        instance = [HKShareAvaudioManager new];
    });
    return instance;
}

- (instancetype)init {
    if (self = [super init]) {
        AVAudioSession *audioSession = [AVAudioSession sharedInstance];
        [audioSession setCategory:AVAudioSessionCategoryPlayAndRecord error:nil];
        [audioSession setActive:YES error:nil];
    }
    return self;
}

- (void)playWithUrl:(NSURL *)url {
    if (!url) {
        return;
    }
    [self.Player stop];
    self.Player =[[AVAudioPlayer alloc]initWithContentsOfURL:url error:nil];
    if (self.Player) {
        [self.Player play];
    }
}

@end
